<?php
// $Id: index_action.php 98 2008-02-28 21:45:09Z mikhail.miguel $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
// ------------------------------------------------------------------------- //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //

include_once "../../../mainfile.php";
include_once "../header.php";


$xoopsOption['theme_use_smarty'] = 1;
// include Smarty template engine and initialize it
require_once XOOPS_ROOT_PATH.'/class/template.php';
$xoopsTpl = new XoopsTpl();
$xoopsTpl->xoops_setCaching(2);
if ($xoopsConfig['debug_mode'] == 3) {
	$xoopsTpl->xoops_setDebugging(true);
}


if ( !empty($_POST['submit']) ) {


    $myts =& MyTextSanitizer::getInstance();
    $usersEmail = $myts->stripSlashesGPC($_POST['usersEmail']);
	if(!checkEmail($usersEmail)) {
		// ToDo: use message catalog
		message_header("index.php",2,"EMAIL ERROR");
		exit();
	}


    $usersCompanyName = $myts->stripSlashesGPC(ajax_convert_encoding($_POST['usersCompanyName'], $to = _CHARSET, $from = 'UTF-8'));
    $usersCompanyLocation = $myts->stripSlashesGPC(ajax_convert_encoding($_POST['usersCompanyLocation'], $to = _CHARSET, $from = 'UTF-8'));
    $usersComments = $myts->stripSlashesGPC(ajax_convert_encoding($_POST['usersComments'], $to = _CHARSET, $from = 'UTF-8'));
    $usersName = $myts->stripSlashesGPC(ajax_convert_encoding($_POST['usersName'], $to = _CHARSET, $from = 'UTF-8'));

    $adminMessage = sprintf(_CT_SUBMITTED,$usersName);
    $adminMessage .= "\n";
    $adminMessage .= ""._CT_EMAIL." $usersEmail\n";
    if ( !empty($_POST['usersSite']) ) {
        $adminMessage .= _CT_URL." ".$myts->stripSlashesGPC(ajax_convert_encoding($_POST['usersSite'], $to = _CHARSET, $from = 'UTF-8'))."\n";
    }
    if ( !empty($_POST['usersICQ']) ) {
        $adminMessage .= _CT_ICQ." ".$myts->stripSlashesGPC(ajax_convert_encoding($_POST['usersICQ'], $to = _CHARSET, $from = 'UTF-8'))."\n";
    }
    if ( !empty($usersCompanyName) ) {
        $adminMessage .= _CT_COMPANY. " $usersCompanyName\n";
    }
    if ( !empty($usersCompanyLocation) ) {
        $adminMessage .= _CT_LOCATION." $usersCompanyLocation\n";
    }
    $adminMessage .= _CT_COMMENTS."\n";
    $adminMessage .= "\n$usersComments\n";
    $adminMessage .= "\n".$_SERVER['HTTP_USER_AGENT']."\n";
    $subject = $xoopsConfig['sitename']." - "._CT_CONTACTFORM;

    $xoopsMailer =& getMailer();
    $xoopsMailer->useMail();
    $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
    $xoopsMailer->setFromEmail($usersEmail);
    $xoopsMailer->setFromName($xoopsConfig['sitename']);
    $xoopsMailer->setSubject($subject);
    $xoopsMailer->setBody($adminMessage);
    $xoopsMailer->send();
   
 $messagesent = sprintf(_CT_MESSAGESENT,$xoopsConfig['sitename'])."<br />"._CT_THANKYOU."";

    // uncomment the following lines if you want to send confirmation mail to the user
   /*
    $conf_subject = _CT_THANKYOU;
    $userMessage = sprintf(_CT_HELLO,$usersName);
    $userMessage .= "\n\n";
    $userMessage .= sprintf(_CT_THANKYOUCOMMENTS,$xoopsConfig['sitename']);
    $userMessage .= "\n";
    $userMessage .= sprintf(_CT_SENTTOWEBMASTER,$xoopsConfig['sitename']);
    $userMessage .= "\n";
    $userMessage .= _CT_YOURMESSAGE."\n";
    $userMessage .= "\n$usersComments\n\n";
    $userMessage .= "--------------\n";
    $userMessage .= "".$xoopsConfig['sitename']." "._CT_WEBMASTER."\n";
    $userMessage .= "".$xoopsConfig['adminmail']."";
    $xoopsMailer =& getMailer();
    $xoopsMailer->useMail();
    $xoopsMailer->setToEmails($usersEmail);
    $xoopsMailer->setFromEmail($usersEmail);
    $xoopsMailer->setFromName($xoopsConfig['sitename']);
    $xoopsMailer->setSubject($conf_subject);
    $xoopsMailer->setBody($userMessage);
    $xoopsMailer->send();
    $messagesent .= sprintf(_CT_SENTASCONFIRM,$usersEmail);
  */
    message_header("index.php",2,$messagesent);
    exit();


}
else {

    include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
    $company_v = "";
    $name_v = !empty($xoopsUser) ? $xoopsUser->getVar("uname", "E") : "";
    $email_v = !empty($xoopsUser) ? $xoopsUser->getVar("email", "E") : "";
    $url_v = !empty($xoopsUser) ? $xoopsUser->getVar("url", "E") : "";
    $icq_v = !empty($xoopsUser) ? $xoopsUser->getVar("user_icq", "E") : "";
    $location_v = !empty($xoopsUser) ? $xoopsUser->getVar("user_from", "E") : "";
    $comment_v = "";
    include XOOPSCONTACTPATH."/contactform.php";
    $contact_form->assign($xoopsTpl);

        if (!headers_sent()) {
            header('Content-Type:text/html; charset='._CHARSET);
            header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
            header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
            header('Cache-Control: no-store, no-cache, must-revalidate');
            header('Cache-Control: post-check=0, pre-check=0', false);
            header('Pragma: no-cache');
        }

    $xoopsTpl->xoops_setCaching(0);
    $xoopsTpl->display(XOOPSCONTACTPATH.'/templates/result_contactusform.html');
}
?>